package com.woniuxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.work.framework.pojo.BiddingRecord;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * @author kyle
 * @date 2019-09-18 12:16
 */
@Api(value = "竞拍相关的crud")
@Repository
@Mapper
public interface BiddingRecordMapper extends BaseMapper<BiddingRecord> {

    @Insert("insert into bidding_record (status, price, uid, aid,nickname) values (#{status},#{price},#{uid},#{aid},#{nickname})")
    boolean addBiddingRecord(BiddingRecord biddingRecord);

    @Insert("update bidding_record set status = #{status} where uid = #{uid} and aid = #{aid}")
    boolean updateBiddingRecord(BiddingRecord biddingRecord);

    @Insert("update bidding_record set status = #{statusNow} where status = #{statusOld} and aid = #{aid}")
    boolean updateBiddingRecordByAid(@PathParam("aid") Integer aid,@PathParam("statusOld")Integer statusOld,@PathParam("statusNow")Integer statusNow);

    @Select("select rid, status, max(price) price, auction_time auctionTime, uid, aid from bidding_record where aid=#{aid} and flage=1")
    BiddingRecord findMaxPriceByUidAndAid(BiddingRecord record);

    @Select("select rid, status,price, auction_time auctionTime, uid, aid,nickname from bidding_record where aid=#{aid} and flage=1")
    List<BiddingRecord> selectBiddingRecords(Integer aid);
}
